﻿#region Header

/*
    This file is part of nDoctor Light

    NDoctor is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    NDoctor is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with NDoctor.  If not, see <http://www.gnu.org/licenses/>.
*/

#endregion Header

namespace Probel.Ldoc.Views.Pages
{
    using System;
    using System.Windows.Controls;

    using Probel.Ldoc.Services.Dto;
    using Probel.Ldoc.ViewModels.Pages;
    using Probel.Ldoc.Views.Controls;
    using Probel.Ldoc.Views.Controls.Correctors;

    /// <summary>
    /// Interaction logic for IncoherencesView.xaml
    /// </summary>
    public partial class IncoherencesView : Page
    {
        #region Constructors

        public IncoherencesView(IncoherencesViewModel viewmodel)
        {
            InitializeComponent();
            this.DataContext = viewmodel;
        }

        #endregion Constructors

        #region Properties

        private IncoherencesViewModel ViewModel
        {
            get { return this.DataContext as IncoherencesViewModel; }
        }

        #endregion Properties

        #region Methods

        private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count != 1) { return; }

            var error = e.AddedItems[0] as IncoherenceDto;

            switch (error.FixType)
            {
                case FixType.SpellingInsurance:
                    this.frame.Content = new InsuranceSpellingCorectorView(this.ViewModel.BuildInsuranceSpellingCorectorViewModel());
                    break;
                case FixType.SpellingProfession:
                    this.frame.Content = new ProfessionSpellingCorrectorView(this.ViewModel.BuildProfessionSpellingCorrectorViewModel());
                    break;
                case FixType.SpellingReputation:
                    this.frame.Content = new ReputationSpellingCorrectorView(this.ViewModel.BuildReputationSpellingCorrectorViewModel());
                    break;
                case FixType.LowerCaseInsurance:
                    this.frame.Content = new LowerCaseCorectorView(this.ViewModel.BuildInsuranceLowerCaseViewModel());
                    break;
                case FixType.LowerCaseProfession:
                    this.frame.Content = new LowerCaseCorectorView(this.ViewModel.BuildProfessionLowerCaseViewModel());
                    break;
                case FixType.LowerCaseReputation:
                    this.frame.Content = new LowerCaseCorectorView(this.ViewModel.BuildReputationLowerCaseViewModel());
                    break;
                case FixType.LowerCasePractice:
                    this.frame.Content = new LowerCaseCorectorView(this.ViewModel.BuildPracticeLowerCaseViewModel());
                    break;
                default:
                    throw new NotSupportedException(string.Format("This fix '{0}' doesn't exist", error.FixType));
            }
        }

        #endregion Methods
    }
}